// app/api/todos/[id]/route.ts
import { NextRequest, NextResponse } from "next/server";
import { toggleTodo, removeTodo } from "../../../../../lib/todos";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function PATCH(req: NextRequest, { params }: { params: { id: string } }) {
const url = new URL(req.url);
const doneParam = url.searchParams.get("done");
const done = doneParam === null ? undefined : doneParam === "true";
try {
const t = await toggleTodo(params.id, done);
return NextResponse.json(t);
} catch {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
}
export async function DELETE(_req: NextRequest, { params }: { params: { id: string } }) {
await removeTodo(params.id);
return NextResponse.json({ ok: true });
}